package com.xl.qa.enmus;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.experimental.Accessors;

import java.util.Arrays;
import java.util.List;

/**
 * @author 钟勇
 * Create in 2024/1/15 16:54
 */
@Getter
@Accessors(chain = true)
@AllArgsConstructor
public enum QuestionTypeEnums {
    text(1, "文本", 0),
    textarea(2, "文本域", 0),
    select(3, "下拉框", 1),
    date(4, "日期", 0),
    image(5, "图片上传", 0),
    provincesAndCity(6, "省份城市", 0),

    ;
    private final Integer type;
    private final String title;
    private final Integer scopeFlag;

    public static QuestionTypeEnums getByType(Integer type) {
        if (type == null) {
            return null;
        }

        return Arrays.stream(values())
                .filter(item -> item.getType().equals(type))
                .findFirst().orElse(null);

    }

    public static List<QuestionTypeVo> queryQuestionTypeList() {
        return Arrays.stream(values()).map(
                item -> new QuestionTypeVo(item.type, item.title, item.scopeFlag)
        ).toList();
    }

    @Accessors(chain = true)
    public record QuestionTypeVo(Integer type, String title, Integer scopeFlag) {
    }

}
